package edu.iul.daam.rap;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MenuActivity extends Activity implements OnClickListener{

	Button buttondevelop,buttonstart,buttonoptions,buttonlastview,buttonexit;
	ProgressDialog progressDialog;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);

		buttonstart = (Button) findViewById(R.id.menubuttonstart);
		buttonstart.setOnClickListener(this);
		buttonoptions = (Button) findViewById(R.id.menubuttonoptions);
		buttonoptions.setOnClickListener(this);
		buttonlastview = (Button) findViewById(R.id.menubuttonlastviews);
		buttonlastview.setOnClickListener(this);
		buttondevelop = (Button) findViewById(R.id.menubuttondevelopers);
		buttondevelop.setOnClickListener(this);
		buttonexit = (Button) findViewById(R.id.menubuttonexit);
		buttonexit.setOnClickListener(this);

		startProgessBar();
	}

	private void startProgessBar() {
		progressDialog = ProgressDialog.show(MenuActivity.this, "", "Loading...");

		new Thread() {

			public void run() {

				try{

					sleep(5000);

				} catch (Exception e) {

					Log.e("tag", e.getMessage());

				}

				progressDialog.dismiss();

			}
		}.start();

	}

	public void onClick(View view) {
		switch(view.getId()){

		case R.id.menubuttonstart:
			startActivity(new Intent(this,WindowTextActivity.class));
			break;
		case R.id.menubuttonoptions:
			startActivity(new Intent(this,MenuOptionsActivity.class));
			break;
		case R.id.menubuttonlastviews:
			break;
		case R.id.menubuttondevelopers:
			new AlertDialog.Builder(MenuActivity.this).setTitle("Developers").setIcon(R.drawable.ic_launcher)
			.setMessage("This program was developed by Jorge Cunha & Tiago Brito").setNeutralButton("Close", null).create().show();
			break;
		case R.id.menubuttonexit:
			new AlertDialog.Builder(MenuActivity.this).setTitle("Exit").setMessage("Are you sure that you want to quit?")
			.setPositiveButton("Yes",  new DialogInterface.OnClickListener(){
				public void onClick(DialogInterface dialog, int whichButton) {
					finish();
				}              
			})
			.setNegativeButton("No", new DialogInterface.OnClickListener() { 
				public void onClick(DialogInterface dialog, int whichButton) {
				}})
				.create().show();
			break;
		}
	}
}
